<template>
  <template v-if="user">
    <van-cell title="id" :value='user.id'/>
    <van-cell title="昵称" is-link to="/user/edit" :value="user.username" @click="toEdit('username',user.username,'昵称')"  />
    <van-cell title="账号" :value="user.userAccount" />
    <van-cell title="介绍" is-link :value="user.profile"@click="toEdit('profile',user.profile,'介绍')"   />
    <van-cell title='头像' is-link to="/user/edit" @click="toEdit('userAvatar',user.userAvatar,'头像')">
      <img style="height: 40px" :src="user.userAvatar"/>
    </van-cell>
    <van-cell title='性别' is-link to="/user/edit" :value="user.gender===0? '男':'女'" @click="toEdit('gender',user.gender,'性别')" />
    <van-cell title="电话" is-link to="/user/edit" :value='user.phone' @click="toEdit('phone',user.phone,'电话')" />
    <van-cell title='邮箱' is-link to="/user/edit" :value='user.email' @click="toEdit('email',user.email,'邮箱')"  />
    <van-cell title="创建时间" :value='formatDate(user.createTime)'/>
  </template>
  <van-empty v-if="!user" description="暂未登录"/>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../services/user.ts";
import {formatDate} from "../../utils/Date";
const router = useRouter();
const user=ref({})

onMounted(async ()=>{
  //获取登录用户信息 一定要加上await 不然获取的是一个axios封装的对象
  user.value=await getCurrentUser()
})

//跳转编辑页面
const toEdit=(editKey:string,currentKey:string,editName:string)=>{
  router.push({
    path:'/user/edit',
    //传递参数
    query:{
      editKey,
      currentKey,
      editName
    }
  })

}

</script>

<style scoped>

</style>